﻿using LD.Common;
using LD.Host.Sqlguar;
using ReaLTaiizor.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Host
{
    public partial class FrmJGTestSearch : BaseFrm
    {
        public FrmJGTestSearch()
        {
            InitializeComponent();
            GetLang(this.Controls);
            this.Text = Language.GetString("FrmJGTestSearch.Name");
        }

        private void GetLang(Control.ControlCollection _controls)
        {
            foreach (Control control in _controls)
            {
                GetLang(control.Controls);
                if (control is Label)
                {
                    string value = Language.GetString("FrmJGTestSearch." + control.Name);
                    if (!string.IsNullOrEmpty(value))
                        control.Text = Language.GetString("FrmJGTestSearch." + control.Name);
                }
                else if (control is MaterialButton)
                {
                    control.Text = Language.GetString("FrmJGTestSearch." + control.Name);
                }
                else if (control is DataGridView)
                {
                    DataGridView dataGridView = (DataGridView)control;
                    foreach (var item in dataGridView.Columns)
                    {
                        if (item is DataGridViewTextBoxColumn)
                        {
                            DataGridViewTextBoxColumn column = (DataGridViewTextBoxColumn)item;
                            column.HeaderText = Language.GetString("FrmJGTestSearch." + column.Name);
                        }
                    }
                }
            }
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            var dataList = DBHelper.Instance.Sql.Queryable<TB_PointCheck>()
                .Where(p => p.CreateTime >= this.dateTimeS.Value && p.CreateTime <= this.dateTimeE.Value)
                .WhereIF(!string.IsNullOrEmpty(this.txt_partNo.Text), p => p.PartNo == this.txt_partNo.Text)
                .WhereIF(!string.IsNullOrEmpty(this.txt_barcode.Text), p => p.Barcode == this.txt_barcode.Text)
                .ToList();
            this.dgv_data.DataSource = dataList;
        }
    }
}
